package com.kktestspb.demo.services;

import com.kktestspb.demo.domain.ScrapDomain;
import com.kktestspb.demo.polo.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Service
public class PCServices {

    @Autowired
    ScrapDomain scrapDomain;


        /**
         * 爬取天猫欧诗漫产品销量(月销量前十名)
         * @return
         */
        public List<Product> getTmallOsmInfo(){
            List<Product> products=new ArrayList<>();
            products=scrapDomain.getTest2();
            Collections.sort(products, new Comparator<Product>() {
                @Override
                public int compare(Product o1, Product o2) {
                    return o2.getProMonthAmout().compareTo(o1.getProMonthAmout());
                }
            });
            return products;
        }
    /**
     * 爬取天猫欧诗漫产品销量(月销量前十名)
     * @return
     */
    public List<Product> getTopTen(){
        List<Product> products=new ArrayList<>();
        List<Product> sreproducts=new ArrayList<>();
        products=scrapDomain.getTest2();
        Collections.sort(products, new Comparator<Product>() {
            @Override
            public int compare(Product o1, Product o2) {
                return o2.getProMonthAmout().compareTo(o1.getProMonthAmout());
            }
        });
        //获取月销售额排名前十的数据
        sreproducts=products.subList(0,10);
//        for(Product p:sreproducts){
//            System.out.println(p.toString());
//        }
        return sreproducts;
    }

//    public static void main(String[] args) {
//        getTest2();
//
//    }




}
